<template>
  <a-modal
    title="创建新商户"
    :visible="visible"
    @ok="onSubmit"
    @cancel="visible = false"
  >
    <a-form-model
      ref="ruleForm"
      :model="form"
      :rules="rules"
      :label-col="{ span: 6 }"
      :wrapper-col="{ span: 14 }"
    >
      <a-form-model-item ref="username" label="用户名" prop="username">
        <a-input v-model="form.username" />
      </a-form-model-item>

      <!-- <a-form-model-item label="编码" prop="code">
        <a-input v-model="form.code" />
      </a-form-model-item> -->

      <a-form-model-item label="手机号" prop="mobile">
        <a-input v-model="form.mobile" />
      </a-form-model-item>

      <a-form-model-item label="密码">
        <a-input default-value="88888888" disabled />
      </a-form-model-item>

      <a-form-model-item ref="fee_ratio" label="买币手续费" prop="fee_ratio">
        <a-input-number
          v-model="form.fee_ratio"
          :step="0.001"
          :min="0"
          :max="max_fee"
        />
      </a-form-model-item>

      <a-form-model-item ref="tip" label="下发手续费" prop="tip">
        <a-input-number v-model="form.tip" :min="0" :max="max_tip" />
      </a-form-model-item>
    </a-form-model>
  </a-modal>
</template>
<script>
import { mapGetters } from 'vuex'

export default {
  data() {
    return {
      visible: false,
      max_fee: 0,
      max_tip: 0,
      form: {
        username: '',
        fee_ratio: 0,
        tip: 0,
        mobile: '',
        // code: '',
      },
      rules: {
        username: [
          {
            required: true,
            message: '请输入',
            trigger: 'blur',
          },
          {
            min: 6,
            message: '请输入',
            trigger: 'blur',
          },
        ],
        fee_ratio: [
          {
            required: true,
            message: '请输入',
            trigger: 'blur',
          },
        ],
        tip: [
          {
            required: true,
            message: '请输入',
            trigger: 'blur',
          },
        ],
      },
    }
  },
  computed: {
    ...mapGetters('account', ['sys']),
  },
  methods: {
    show() {
      this.max_fee = this.sys.global_fee_ratio
      this.max_tip = this.sys.global_tip
      //   console.log(this.sys)
      this.visible = true
    },
    onSubmit() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          this.axios.post('/sellers', this.form).then((res) => {
            if (res.data.code === 1) {
              this.visible = false
              this.$message.success('创建成功')
              this.$emit('refresh')
            } else {
              this.$message.error(res.data.msg)
            }
          })
          //   alert('submit!')
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
  },
}
</script>
